package LeetCode.exercise;

public class LC75 {
    public static void main(String[] args) {
        LC75 l = new LC75();
        l.sortColors(new int[]{2,0,2,1,1,0});
    }
    public void sortColors(int[] nums) {
        int left = -1, right = nums.length;
        for(int i = 0; i < right;){
            if(nums[i] == 0){
                swap(nums, ++left, i++);
            } else if(nums[i] == 1){
                i++;
            } else {
                swap(nums, --right, i);
            }
        }
    }
    public void swap(int[] array, int i, int j){
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
}
